package J02treeset;

import java.util.TreeSet;

public class J3sort {
    public static void main(String[] args) {
//        TreeSet<Integer> arr = new TreeSet<>();
        TreeSet<Integer> arr = new TreeSet<>(
                (num1,num2)->{
                    //乱序
                    if(Math.random()>0.5){
                        return num2-num1;
                    }else {
                        return num1-num2;
                    }
                }
        );
        arr.add(5);
        arr.add(3);
        arr.add(8);
        arr.add(2);
        System.out.println("arr = " + arr);
    }
}

class Dog{
    int age;
    String name;

    public Dog(int age, String name) {
        this.age = age;
        this.name = name;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}
class DogSort{
    public static void main(String[] args) {
//        TreeSet<Dog> arr = new TreeSet<>(
//                (d1,d2)->d1.age-d2.age
//        );
        TreeSet<Dog> arr = new TreeSet<>(
                (d1,d2)->d2.name.compareTo(d1.name)
        );
        arr.add(new Dog(2,"a哈士奇"));
        arr.add(new Dog(7,"m法拉利"));
        arr.add(new Dog(4,"c田园全"));

        System.out.println("arr = " + arr);
    }
}